home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-12 | 11.7 KB | 403 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Content.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "IntlTest.hpp"
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- // --- Framework Includes ---
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- // --- OpenDoc Includes ---
-
- // for ODSetITextProp
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- // ----- Macintosh Includes -----
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfIntlTest
- #endif
-
- //========================================================================================
- // Global Functions
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // InternalizeIntlText
- //----------------------------------------------------------------------------------------
- FW_Boolean InternalizeIntlText(Environment* ev, ODStorageUnit* storageUnit, FW_CString& textData)
- {
- FW_Boolean result = false;
- ODIText* iText = ODGetITextProp(ev, storageUnit, kODPropContents, kODMacIText, NULL);
- if (iText)
- {
- textData.ReplaceAll(iText);
- /* Do we need to free the iText? */
- result = true;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // InternalizeText
- //----------------------------------------------------------------------------------------
- FW_Boolean InternalizeText(Environment* ev, ODStorageUnit* storageUnit, FW_CString& textData)
- {
- FW_Boolean result = false;
-
- #ifdef FW_BUILD_MAC
- unsigned long textSize = storageUnit->GetSize(ev);
- if (textSize > 0)
- {
- char buffer[256];
- if (textSize > 255)
- textSize = 255;
- FW_CByteArray byteArray;
- storageUnit->GetValue(ev, textSize, byteArray);
- byteArray.CopyBuffer(&buffer, textSize);
-
- textData = "";
- textData.Append((const FW_Char*) &buffer, textSize);
-
- result = TRUE;
- }
- #endif
-
- return result;
- }
-
- //========================================================================================
- // CIntlTestContent class
- //========================================================================================
-
- FW_DEFINE_AUTO(CIntlTestContent)
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent constructor
- //----------------------------------------------------------------------------------------
- CIntlTestContent::CIntlTestContent(Environment* ev, CIntlTestPart* part) :
- FW_CContent(ev, part),
- fEnglishText(""),
- fJapaneseText("", gJapaneseLocale),
- fIntlTestPart(part)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent destructor
- //----------------------------------------------------------------------------------------
-
- CIntlTestContent::~CIntlTestContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent::GetTextData
- //----------------------------------------------------------------------------------------
-
- const FW_CString& CIntlTestContent::GetTextData(ODID whichView)
- {
- if (whichView == kJapaneseEditView)
- return fJapaneseText;
-
- return fEnglishText;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent::SetTextData
- //----------------------------------------------------------------------------------------
-
- void CIntlTestContent::SetTextData( Environment*,
- const FW_CString& newText,
- ODID whichView)
- {
- if (whichView == kJapaneseEditView)
- fJapaneseText = newText;
- else
- fEnglishText = newText;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent::Externalize
- //----------------------------------------------------------------------------------------
-
- void CIntlTestContent::ExternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CPromise* promise,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
- FW_UNUSED(promise);
- FW_UNUSED(cloneInfo);
-
- if (kind->IsPartKind(ev))
- {
- // Update the strings from the edit views, if we have any
- fIntlTestPart->UpdateTextData(ev);
- ExternalizePartKind(ev, storageUnit, kind->GetType(ev));
- }
- else if (kind->IsEqual(ev, kODMacIText))
- {
- // Write the main string as an ODIText
- ODSetITextProp(ev, storageUnit, kODPropContents, kODMacIText, fEnglishText.RevealODIText());
- }
- else if (kind->IsEqual(ev, kTEXTOSType, kODPlatformDataType))
- {
- // Write the main string in Mac 'TEXT' format
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
- FW_CWritableStream stream(suSink);
- stream.Write(fEnglishText.RevealBuffer(), fEnglishText.GetByteLength());
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent::ExternalizePartKind
- //----------------------------------------------------------------------------------------
-
- void CIntlTestContent::ExternalizePartKind(Environment* ev, ODStorageUnit* storageUnit,
- ODType partKind)
- {
- // Write the three text data strings to storage
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, partKind);
- FW_CWritableStream archive(suSink);
-
- unsigned long stringCount = 2;
- archive << stringCount;
-
- unsigned long whichString = kEnglishEditView;
- archive << whichString;
- archive << fEnglishText;
-
- whichString = kJapaneseEditView;
- archive << whichString;
- archive << fJapaneseText;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent::InternalizeKind
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CIntlTestContent::InternalizeKind(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
-
- FW_Boolean internalized = FALSE;
-
- if (kind->IsPartKind(ev))
- {
- internalized = InternalizePartKind(ev, sourceSU, kind->GetType(ev));
- }
- else if (kind->IsEqual(ev, kODMacIText))
- {
- internalized = InternalizeIntlText(ev, sourceSU, fEnglishText);
- }
- else if (kind->IsEqual(ev, kTEXTOSType, kODPlatformDataType))
- {
- internalized = InternalizeText(ev, sourceSU, fEnglishText);
- }
-
- return internalized;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestContent::InternalizePartKind
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CIntlTestContent::InternalizePartKind(Environment* ev, ODStorageUnit* storageUnit,
- ODType partKind)
- {
- FW_Boolean internalized = TRUE;
-
- if (storageUnit->GetSize(ev) != 0)
- {
- // Read the text data strings from storage
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, partKind);
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream archive(sink);
-
- unsigned long stringCount, whichString;
- archive >> stringCount;
- for (unsigned long i = 0; i < stringCount; i++)
- {
- archive >> whichString;
- if (whichString == kJapaneseEditView)
- archive >> fJapaneseText;
- else
- archive >> fEnglishText;
- }
- }
-
- return internalized;
- }
-
- //========================================================================================
- // CIntlTestSelectedContent class
- //========================================================================================
-
- FW_DEFINE_AUTO(CIntlTestSelectedContent)
-
- //----------------------------------------------------------------------------------------
- // CIntlTestSelectedContent constructor
- //----------------------------------------------------------------------------------------
- CIntlTestSelectedContent::CIntlTestSelectedContent(Environment* ev, CIntlTestPart* part) :
- FW_CContent(ev, part),
- fIntlTestPart(part),
- fEditView(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestSelectedContent destructor
- //----------------------------------------------------------------------------------------
-
- CIntlTestSelectedContent::~CIntlTestSelectedContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestSelectedContent::ExternalizeKind
- //----------------------------------------------------------------------------------------
-
- void CIntlTestSelectedContent::ExternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CPromise* promise,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
- FW_UNUSED(promise);
- FW_UNUSED(cloneInfo);
-
- FW_CString selectedText;
- GetSelectedText(ev, selectedText);
-
- if (kind->IsEqual(ev, kODMacIText))
- {
- // Write the selected string as an ODIText
- ODSetITextProp(ev, storageUnit, kODPropContents, kODMacIText, selectedText.RevealODIText());
- }
- else if (kind->IsEqual(ev, kTEXTOSType, kODPlatformDataType))
- {
- // Write the selected string in Mac 'TEXT' format
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
- FW_CWritableStream stream(suSink);
- stream.Write(selectedText.RevealBuffer(), selectedText.GetByteLength());
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestSelectedContent::InternalizeKind
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CIntlTestSelectedContent::InternalizeKind(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
- FW_Boolean internalized = false;
- FW_CString selectedText;
-
- if (kind->IsEqual(ev, kODMacIText))
- {
- internalized = InternalizeIntlText(ev, sourceSU, selectedText);
- }
- else if (kind->IsEqual(ev, kTEXTOSType, kODPlatformDataType))
- {
- internalized = InternalizeText(ev, sourceSU, selectedText);
- }
-
- if (internalized)
- {
- fInternalizedText = selectedText;
- this->SetSelectedText(ev, selectedText);
- }
-
- return internalized;
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestSelectedContent::GetSelectedText(Environment* ev, FW_CString& text)
- {
- if (fEditView == NULL)
- text = "";
- else
- text = fEditView->GetSelectedText(ev);
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestSelectedContent::SetSelectedText(Environment* ev, const FW_CString& newText)
- {
- FW_ASSERT(fEditView);
- fEditView->SetSelectedText(ev, newText);
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestSelectedContent::ClearSelectedText(Environment* ev)
- {
- FW_ASSERT(fEditView);
- fEditView->SetSelectedText(ev, FW_CString());
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestSelectedContent::SetSelectionRange(Environment* ev, short startOffset, short endOffset)
- {
- if (fEditView)
- fEditView->SelectText(ev, startOffset, endOffset);
- }
-